package cn.wolfcode.trip.base.domain;

import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
public class NewsPage extends BaseDomain {

    public static final int STATE_COMMON = 0;//草稿
    public static final int STATE_RELEASE = 1;//发布
    public static final int STATE_HOT = 2;//热门
    public static final int STATE_DISABLE = -1;//禁用

    //标题
    private String title;
    //背景

    private String coverUrl;
    //状态
    private Integer state;
    //创建时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date creadTime;
    //内容
    private String content;
    //收藏数量
    private Integer collectNum;

    public String getStateName() {
        String temp = "草稿";
        if (STATE_RELEASE == state) {
            temp = "发布";
        } else if (STATE_DISABLE == state) {
            temp = "禁用";
        }else if (STATE_HOT == state) {
            temp = "大热门";
        }

        return temp;
    }


    public String getJson() {
        HashMap<String, Object> map = new HashMap<>(10);
        map.put("id", id);
        map.put("title", title);
        map.put("coverUrl", coverUrl);
        map.put("state", state);
        map.put("content", content);
        map.put("collectNum", collectNum);
        return JSON.toJSONString(map);
    }
}